"""
通用工具类
"""
import json

import config
from api.ihrm_login_Api import LoginApi


class CommonUtil(object):
    @classmethod
    def assert_util(cls, self, resp, status_code, success, code, message):
        """
        通用断言方法
        """
        self.assertEqual(status_code, resp.status_code)
        self.assertEqual(success, resp.json().get("success"))
        self.assertEqual(code, resp.json().get("code"))
        self.assertIn(message, resp.json().get("message"))

    @classmethod
    def build_data_util(cls, file_path):
        # 读取json文件
        with open(file_path, mode="r", encoding="utf8") as f:
            json_data = json.load(f)
            # 创建空列表
            case_data = []
            # 循环提取每组数据
            for data in json_data:
                # 转换为 元组
                tmp = tuple(data.values())
                # 追加到 列表
                case_data.append(tmp)
            # 返回 [(),()...]
            return case_data

    @classmethod
    def get_header(cls):
        resp = LoginApi.login(config.LOGIN_SUCCESS_DATA)
        token = "Bearer " + resp.json().get("data")
        header = {"Authorization": token}
        return header


if __name__ == '__main__':
    # case_data = CommonUtil.build_data_util()
    # print(case_data)
    CommonUtil.get_header()